<?php	
	
	//SCRIPT IS FILLED BY POST FROM FORM
	//USED BY AJAX REQUEST
	//THEREFORE LIVE UPDATING AVAILABLE
	
	
	
	$error = 0; //SET ERROR TO FALSE
	
	//defining Variables (only done to better compare the original C# Code to PHP)
    $uno = 0;
    $due = 0;
    $tre = 0;
    $quattro = 0;
    $cinque = 0;
    $sei = 0;
    $sette = 0;
    $otto = 0;
    $nove = 0;
    $dieci = 0;
    $minuti_ricarica = 0;
	
	
	//Assigning the Values from the form to the Variables
	//(int) done for better comparison of C# to PHP
	$uno = 		(int)$_POST['refn1'];
	$due = 		(int)$_POST['refn2'];
	$tre = 		(int)$_POST['refn3'];
	$quattro =  (int)$_POST['refn4'];
	$cinque = 	(int)$_POST['refn5'];
	$sei	=	(int)$_POST['refn6'];
	
	$sette = 	(int)$_POST['id2n7'];
	$otto = 	(int)$_POST['id2n8'];

	$nove = 	(int)$_POST['id1n9'];
	$dieci =	(int)$_POST['id1n10'];
	
	$minuti_ricarica = (int)$_POST['recMinutesCount'];
		
	//Validation rules
	//in C# Source LINE 41++	
	if($dieci >= $nove){
		$error = "ERROR #1";
	}
	if($otto + $minuti_ricarica >= $nove){
		$error =  "ERROR #2";
	}
	
	
	
	
	//C# Source:	LINE 55++
	(int)$a = $uno + $due + $tre + $quattro + $cinque + $sei;
	(int)$b = $sette + $minuti_ricarica;
	(int)$c = $nove - $b;
	(int)$d = (int)$b ^ (int)$a;
	(int)$f = (int)$c ^ (int)$a;
	
	//DEBUG
	/*
	echo "<br>a: ".$a;
	echo "<br>b: ".$b;
	echo "<br>c: ".$c;
	echo "<br>d: ".$d;
	echo "<br>f: ".$f;
	*/
	
	//VALIDATION
	//C# Source:	LINE 61++
	if(((int)$a < 0) || ((int)$a > 65535)){
		$error = "ERROR #10";
	}
	if(((int)$d < 0) || ((int)$b > 65535)){
		$error = "ERROR #11";	
	}
	if(((int)$f < 0) || ((int)$c > 65535)){
		$error = "ERROR #12";
	}

	//C#:			LINE 67 
	$code = (int)$a.".".(int)$d.".".(int)$f;


	//OUTPUT FOR PHP
	if(empty($error)){
		echo '<span class="code">'.$code.'</span>';
	} else {
		echo '<span class="error">'.$error.'</span>';
	}

	
?>